package com.ama.service.impl;

import com.ama.dao.CompanyDao;
import com.ama.pojo.Company;
import com.ama.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CompanyServiceImp implements CompanyService {
	@Autowired
	CompanyDao companyDao;
	@Override
	public List<Company> listAllCompanies() {
		List<Company> companies = companyDao.findAllCompanies();
		return companies;
	}

	@Override
	public List<Company> listAllCompaniesByParams(Map<String, String> map) {
		List<Company> companies = companyDao.findCompaniesByParams(map);
		return companies;	
	}

	@Override
	public boolean register(Company company) {
		Company c = companyDao.findCompanyByName(company.getUsername());
		if(c==null){
			companyDao.saveCompany(company);
			return true;
		}else{
			return false;
		}
	}

	@Override
	public Company login(String username, String password) {
		Company c = companyDao.findCompanyByNameAndPassword(username, password);		
		if(c!=null){
			return c;
		}else{
			return null;
		}
	}

	@Override
	public void update(Company company) {
		companyDao.updateCompany(company);
	}

	@Override
	public void publish(Company company) {
		companyDao.updatePubTime(company);
	}

	@Override
	public void deleteInfo(Company company) {
		companyDao.ZeroPubTime(company);
	}

	@Override
	public Company query(long id) {
		Company company = companyDao.findCompanyById(id);
		return company;
	}
	
}
